package com.realestate.dao;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;

import com.mysema.query.jpa.JPQLQuery;
import com.mysema.query.jpa.impl.JPAQuery;
import com.realestate.constants.ComUnitName;
import com.realestate.model.BrtbUsers;
import com.realestate.model.QBrtbUsers;
import com.trg.dao.jpa.GenericDAOImpl;

@Repository
public class UsersDaoImpl extends GenericDAOImpl<BrtbUsers, String> implements UsersDao{
	
	@SuppressWarnings("unused")
	private static final Logger LOGGER = Logger.getLogger(UsersDaoImpl.class);
	
	@Override
	@PersistenceContext(unitName = ComUnitName.COM_UNIT)
	public void setEntityManager(EntityManager entityManager) {
		super.setEntityManager(entityManager);
	}
 
	@Override
	public BrtbUsers findUserByUsername(String username) {
		JPQLQuery query = new JPAQuery(em());
		
		QBrtbUsers user = QBrtbUsers.brtbUsers;
		
		query.from(user).where(user.username.eq(username));
		
		BrtbUsers users = query.uniqueResult(user);
		return users;
	}
}
